-----------------------------------
-- Area: Lower Jeuno
-- NPC:  Zauko
-- Involved in Quests: Save the Clock Tower, Community Service
-- @zone 245
-- @pos -3 0 11
-----------------------------------
package.loaded["scripts/zones/Lower_Jeuno/TextIDs"] = nil;
-----------------------------------
require("scripts/globals/keyitems");
require("scripts/globals/titles");
require("scripts/globals/settings");
require("scripts/globals/quests");
require("scripts/zones/Lower_Jeuno/TextIDs");
-----------------------------------
-- onTrade Action
-----------------------------------

function onTrade(player,npc,trade)


		if (trade:hasItemQty(16738,1)) then 
			player:addKeyItem(1995);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1995); -- Sheeting
		    end	
		
		if (trade:hasItemQty(16914,1)) then -- Kunai +1
			player:addKeyItem(1994);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1994); -- Chainwork		
	    end
		if (trade:hasItemQty(17146,1)) then -- Rod +1
			player:addKeyItem(1993);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1993); -- Metal Ensorcellment		
	    end	
		if (trade:hasItemQty(16748,1)) then -- Kukri +1
			player:addKeyItem(1992);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1992); -- Metal Purifacation		
	    end	
		if (trade:hasItemQty(13528,1)) then -- Hope ring
			player:addKeyItem(1994);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1994); -- chainwork		
	    end	
		if (trade:hasItemQty(13527,1)) then -- enerygy ring 
			player:addKeyItem(1995);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1995); -- sheeting			
	    end
		if (trade:hasItemQty(13522,1)) then --  courage ring
			player:addKeyItem(2002);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2002); -- clockwork		
	    end
		
		if (trade:hasItemQty(13524,1)) then -- Balance ring
			player:addKeyItem(2001);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2001); -- gold ensoclment		
	    end	
		if (trade:hasItemQty(13521,1)) then -- reflex ring
			player:addKeyItem(2000);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2000); -- gold purifacation		
	    end
		
		if (trade:hasItemQty(13609,1)) then -- wolf mantle +1
			player:addKeyItem(2018);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2018); -- tanning		
	    end
		
		if (trade:hasItemQty(13219,1)) then -- magic belt +1
			player:addKeyItem(2017);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2017); -- leather ensocellment		
	    end
		
		if (trade:hasItemQty(14174,1)) then -- rider's boots
			player:addKeyItem(2016);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2016); -- leather purification 		
	    end
		
		if (trade:hasItemQty(13061,1)) then -- spike necklace
			player:addKeyItem(2026);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2026); -- filing		
	    end
		
		if (trade:hasItemQty(17033,1)) then -- bone cudgel +1 
			player:addKeyItem(2025);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2025); -- bone ens	
	    end		
		
		if (trade:hasItemQty(13828,1)) then --  horn hairpin +1
			player:addKeyItem(2024);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2024); -- bone purifacation	
	    end	
		
		if (trade:hasItemQty(13601,1)) then -- cotton cape +1
			player:addKeyItem(2010);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2010); -- spining	
	    end		
		
		if (trade:hasItemQty(12538,1)) then -- red cape +1
			player:addKeyItem(2011);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2011); -- fletching	
	    end		
		
		if (trade:hasItemQty(15906,1)) then -- Mohbwa sash +1 
			player:addKeyItem(2009);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2009); -- cloth enso	
	    end	
		
		if (trade:hasItemQty(13190,1)) then -- 
			player:addKeyItem(2008);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2008); -- cloth purifacation	
	    end		
		
		if (trade:hasItemQty(4336,1)) then -- sweet baked apple
			player:addKeyItem(2042);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2042); -- patissier	
	    end	
		
		if (trade:hasItemQty(4341,1)) then -- sunset soup
			player:addKeyItem(2041);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2041); -- noodle kneading
	    end	
		
		if (trade:hasItemQty(4587,1)) then -- broiled trout
			player:addKeyItem(2040);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2040); -- raw fish handling
	    end	
		
		if (trade:hasItemQty(4333,1)) then -- witch soup
			player:addKeyItem(2043);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2043); -- stewpot mastery
	    end	
		
		if (trade:hasItemQty(17373,1)) then -- maple harp +1
			player:addKeyItem(1986);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1986); -- lumberjack
	    end	
		
		if (trade:hasItemQty(17239,1)) then -- republic crossbow
			player:addKeyItem(1987);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1987); -- boltmaker 
	    end	
		
		if (trade:hasItemQty(17142,1)) then -- solid wand
			player:addKeyItem(1985);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1985); -- wood ens
	    end	
		
		if (trade:hasItemQty(17142,1)) then -- oak cudgel +1
			player:addKeyItem(1984);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,1984); -- wood purifacation
	    end	
		
		if (trade:hasItemQty(18732,1)) then -- automation oil +1
			player:addKeyItem(2037);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2037); -- Iatrochemistry
	    end	
		
		if (trade:hasItemQty(16741,1)) then -- poison dagger +1
			player:addKeyItem(2035);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2035); -- Trituration
	    end	
		
		if (trade:hasItemQty(16742,1)) then -- Posion Knife +1
			player:addKeyItem(2032);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2032); -- Anima synth
	    end	
		
		if (trade:hasItemQty(4113,1)) then -- potion +1
			player:addKeyItem(2036);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2036); -- concoction
	    end	
		
		if (trade:hasItemQty(16493,1)) then -- blind dagger +1
			player:addKeyItem(2034);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2034); -- alchemic ens
	    end	
		
		if (trade:hasItemQty(16692,1)) then -- Poison Baghnakhs +1
			player:addKeyItem(2033);
			player:tradeComplete(trade);
			player:messageSpecial(KEYITEM_OBTAINED,2033); -- alchemic purifacation	
	    end				

end; 

-----------------------------------
-- onTrigger Action
-----------------------------------

function onTrigger(player,npc)
	
player:showText(npc,MATOAKA_SHOP_DIALOG);

stock = {1121,300, -- silent oil
	 1254,1300, -- vis powder
         917,300, -- toolbag shihe
         1657,50, -- meat mith
         927,500, -- apple pie
         936,20, -- Boiled Crab
         1134,100, -- teak log
         929,400, -- walnut log
         2291,10, -- willow log
         932,450, -- yew log
         933,450, -- moss
         2184,200, -- imp brz peice
         1588,20400, -- blood heads
         819,300, -- aka egg
         4503,400, -- buub grape
         4274,600, --persik
         693,50000, -- doesnt work
         695,50000, -- doesnt work
         696,50000, -- doesnt work
         0x3c56,50000, -- doesnt work
         0x3dcd,50000, -- doesnt work
         0x383a,50000, -- doesnt work
         0x3679,50000, -- doesnt work
         0x3c58,50000, -- doesnt work
         0x390f,50000, -- doesnt work
         0x3dcf,50000, -- doesnt work
         0x383c,50000, -- doesnt work
         0x3c55,50000, -- doesnt work
         0x39ef,50000, -- doesnt work
         0x3dcc,50000, -- doesnt work
	 0x3839,50000} -- doesnt work

 
showShop(player, STATIC, stock);
end; 

	
-----------------------------------
-- onEventUpdate
-----------------------------------

function onEventUpdate(player,csid,option)
--printf("CSID: %u",csid);
--printf("RESULT: %u",option);
end;

-----------------------------------
-- onEventFinish
-----------------------------------

function onEventFinish(player,csid,option)
--printf("CSID: %u",csid);
--printf("RESULT: %u",option);
-- ClockTower Quest --	
	if(csid == 0x0032) then 
		player:setVar("saveTheClockTowerVar",player:getVar("saveTheClockTowerVar") + 1);
		player:setVar("saveTheClockTowerNPCz2",player:getVar("saveTheClockTowerNPCz2") + 256);
	
---- Community Service Quest ----
	elseif(csid == 0x0074 and option == 0) then -- Quest Start
		player:addQuest(JEUNO,COMMUNITY_SERVICE);
		
	elseif(csid == 0x0075) then -- Quest Finish
		player:completeQuest(JEUNO,COMMUNITY_SERVICE);
		player:addFame(JEUNO,30);
		player:setVar("cService",13)
		player:addTitle(TORCHBEARER);
	
	elseif(csid == 0x0071) then -- Quest Finish (Repeat)
		player:addKeyItem(LAMP_LIGHTERS_MEMBERSHIP_CARD); -- Lamp Lighter's Membership Card
		player:messageSpecial(KEYITEM_OBTAINED,LAMP_LIGHTERS_MEMBERSHIP_CARD);
		player:addFame(JEUNO,15);
		player:setVar("cService",0);
	end
	
end;